<template>
  <view class="report_page">
    <u-navbar auto-back fixed placeholder bgColor="#fff">
      <template #left>
        <view class="navBar">
          <u-icon name="arrow-left" color="#000" size="18"></u-icon>
          <text class="nav_title">数据上报</text>
        </view>
      </template>
    </u-navbar>
    <scroll-view scroll-y class="content" :style="{ height: `calc(100% - ${navBarHeight}px)` }">
      <view class="tips">今日上报昨日经营数据～</view>
      <view class="box_list">
        <view class="store_box" v-for="shop in shopList" :key="shop.id">
          <view class="info_box">
            <view class="line_1">
              <u-avatar class="avatar" shape="square" size="66" :src="shop.doorImg"></u-avatar>
              <view class="info">
                <view class="store_name">{{shop.name}}</view>
                <view class="tags">
                  <view v-if="shop.status === '0'" class="tag active">正常营业</view>
                  <view v-else-if="shop.shopStatus === '1'" class="tag stop">暂停营业</view>
                  <view v-else-if="shop.shopStatus === '2'" class="tag invalid">店铺撤场</view>
                </view>
              </view>
            </view>
            <view class="line_2">
              <text class="label">归属景区：</text>
              <text class="desc">{{shop.jingquName}}</text>
            </view>
            <view class="line_3">
              <text class="label">店铺地址：</text>
              <text class="desc">{{shop.address}}</text>
            </view>
          </view>
          <u-divider></u-divider>
          <view class="btn_box" @click="toReportDetail(shop)">
            <text class="btn active" v-if="shop.unReportNum <= 0">已上报</text>
            <text class="btn" v-else>未上报（{{shop.unReportNum}}）</text>
          </view>
        </view>
      </view>
    </scroll-view>
  </view>
</template>

<script>

import {getQiyeList} from "@/api/shop";

export default {
  data() {
    return {
      shopList: []
    }
  },
  onShow() {
    this.getQiyeList()
  },
  computed: {
    navBarHeight () {
      const platform = uni.getSystemInfoSync().platform
      const statusBarHeight = uni.getSystemInfoSync().statusBarHeight
      let navHeight = 0
      if (['ios', 'devtools'].includes(platform)) {
        navHeight = 44
      } else {
        navHeight = 48
      }
      return navHeight + statusBarHeight
    }
  },
  methods: {
    async getQiyeList () {
      const { code, data, msg } = await getQiyeList({
        auditStatus: '1'
      })
      if (code === 200) {
        this.shopList = data.rows;
      } else {
        this.$modal.msgError(msg)
      }
    },
    toReportDetail(shop) {
      const activeTab = shop.unReportNum > 0 ? '0' : '1'
      uni.navigateTo({
        url: `/pages/settled/reportDetail?id=${shop.id}&name=${shop.name}&activeTab=${activeTab}`
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.report_page {
  width: 100vw;
  height: 100vh;
  background-color: #F3F3F3;
  .navBar {
    display: flex;
    align-items: center;

    .nav_title {
      font-size: 36rpx;
      font-weight: 400;
      color: #000000;
      margin-left: 8rpx;
    }
  }
  .content {
    display: flex;
    flex-direction: column;
    .tips {
      display: flex;
      align-items: center;
      justify-content: center;
      margin-top: 40rpx;
      height: 40rpx;
      font-size: 28rpx;
      font-weight: 400;
      color: #999999;
    }
    .box_list {
      padding: 16rpx;
      .store_box {
        background-color: #fff;
        border-radius: 16rpx;
        padding: 32rpx;
        margin-bottom: 16rpx;

        .info_box {
          .line_1 {
            display: flex;
            align-items: center;
            margin-bottom: 32rpx;
            .avatar {
              width: 112rpx;
              height: 112rpx;
            }
            .info {
              margin-left: 32rpx;
              display: flex;
              flex-direction: column;
              justify-content: space-between;
              .store_name {
                font-size: 36rpx;
                font-weight: 500;
                color: #333333;
                margin-bottom: 16rpx
              }
              .tags {
                display: flex;
                justify-content: flex-start;
                align-items: flex-end;
                .tag {
                  width: auto;
                  padding: 0 8rpx;
                  border-radius: 8rpx;
                  border: 2rpx solid #0E9589;

                  display: flex;
                  align-items: center;
                  justify-content: center;
                }
                .active {
                  color: #0E9589;
                  border-color: #0E9589;
                }
                .stop {
                  color: #F9A006;
                  border-color: #F9A006;
                }
                .invalid {
                  color: #999999;
                  border-color: #999999;
                }
              }
            }
          }
          .line_2, .line_3 {
            margin-bottom: 32rpx;
            .label {
              font-size: 32rpx;
              font-weight: 400;
              color: #999999;
            }
            .desc {
              font-size: 32rpx;
              font-weight: 400;
              color: #333333;
            }
          }
        }
        .btn_box {
          display: flex;
          align-items: center;
          justify-content: center;
          padding: 0 32rpx;
          .btn {
            font-size: 32rpx;
            font-weight: 400;
            color: #ED4545;
          }
          .active {
            color: #01756B;
          }
        }
      }
    }
  }
}
</style>
